import { FMediator } from "../Support/FMediator";
import { getQualifiedClassName } from "../Utility/dx/getQualifiedClassName";

export class MediatorManager
{
    private static currentMediator:FMediator = null;
    private static mediators:{[key:string]:FMediator} = {};

    public static SetCurrentMediator(mediator:FMediator):void
    {
        this.currentMediator = mediator;
    }
    public static AddMediator(mediator:FMediator):void
    {
        let name = getQualifiedClassName(mediator);
        this.mediators[name] = mediator;
    }
    public static GetMediator(mediator?:any):FMediator
    {
        if(mediator==null)return this.currentMediator;
        if(!(typeof mediator === "string"))
            mediator = getQualifiedClassName(mediator);
        return this.mediators[mediator];
    }
    public static RemoveMediator(mediator:FMediator):void
    {
        let name = getQualifiedClassName(mediator);
        delete this.mediators[name];
    }
}
